package org.hpm.common.constant.enums;

import cn.hutool.core.util.ObjectUtil;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 是否枚举
 *
 * @author: jacklin
 * @date: 2021-12-05 13:03
 */
public enum YesOrNo {

    NO(0, "是"),
    YES(1, "否");
    public final Integer code;
    private final String value;

    YesOrNo(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static YesOrNo parse(String code) {
        if (ObjectUtil.isNotNull(code)) {
            Optional<YesOrNo> optional = Arrays.stream(values()).filter(e -> Objects.equals(e.getCode(), code)).findFirst();
            if (optional.isPresent()) {
                return optional.get();
            }
        }
        return null;
    }
}
